package AddonsSheepContoller.Utils;

import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.Plugin;

import java.io.File;
import java.io.IOException;

public class YamlLoader {
    private FileConfiguration yamlIO = null;
    private final Plugin resourcePlugin;

    public YamlLoader(Plugin resourcePlugin) { this.resourcePlugin = resourcePlugin; }
    public FileConfiguration getYamlIO() { return this.yamlIO; }

    public void setCustomYaml(boolean replace, String yamlName) {
        File yamlFileIO = new File(resourcePlugin.getDataFolder(), yamlName);
        if(!yamlFileIO.exists()) {
            yamlFileIO.getParentFile().mkdirs();
            resourcePlugin.saveResource(yamlName, replace);
        }

        yamlIO = new YamlConfiguration();

        try { getYamlIO().load(yamlFileIO); }
        catch(IOException | InvalidConfigurationException e) { e.printStackTrace(); }
    }
}
